package vn.edu.saigontech.ncms.web.study;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateMakeUpTestAction extends AbstractValidator {
	private String finalTestId;
	private String date;
	private String listening;
	private String speaking;
	private String grammar;
	private String reading;
	private String writing;
	private String fee;
	@Override
	public String check() {
		if(Checker.isEmpty(finalTestId)) {
			this.sendKeyError("validator.required", "student");
		}
		if(Checker.isEmpty(date)) {
			this.sendKeyError("validator.required", "testDate");
		}
		if(!Checker.isDate(date, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "testDate", "format.date");
		}
		if(Checker.isEmpty(listening)) {
			listening = "0";
		}
		if(!Checker.isDouble(listening) || !Checker.isInRange(Double.valueOf(listening), 0, 100)) {
			this.sendKeyError("validator.invalid", "listeningScore");
		}
		if(Checker.isEmpty(speaking)) {
			speaking = "0";
		}
		if(!Checker.isDouble(speaking) || !Checker.isInRange(Double.valueOf(speaking), 0, 100)) {
			this.sendKeyError("validator.invalid", "speakingScore");
		}
		if(Checker.isEmpty(grammar)) {
			grammar = "0";
		}
		if(!Checker.isDouble(grammar) || !Checker.isInRange(Double.valueOf(grammar), 0, 100)) {
			this.sendKeyError("validator.invalid", "grammarScore");
		}
		if(Checker.isEmpty(reading)) {
			reading = "0";
		}
		if(!Checker.isDouble(reading) || !Checker.isInRange(Double.valueOf(reading), 0, 100)) {
			this.sendKeyError("validator.invalid", "readingScore");
		}
		if(Checker.isEmpty(writing)) {
			writing = "0";
		}
		if(!Checker.isDouble(writing) || !Checker.isInRange(Double.valueOf(writing), 0, 100)) {
			this.sendKeyError("validator.invalid", "writtenScore");
		}
		
		if(!Checker.isEmpty(fee)) {
			if(!Checker.isDouble(fee)) {
				this.sendKeyError("validator.invalid", "fee");
			}
		}
		return this.toSuccess();
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getListening() {
		return listening;
	}
	public void setListening(String listening) {
		this.listening = listening;
	}
	public String getSpeaking() {
		return speaking;
	}
	public void setSpeaking(String speaking) {
		this.speaking = speaking;
	}
	public String getGrammar() {
		return grammar;
	}
	public void setGrammar(String grammar) {
		this.grammar = grammar;
	}
	public String getReading() {
		return reading;
	}
	public void setReading(String reading) {
		this.reading = reading;
	}
	public String getWriting() {
		return writing;
	}
	public void setWriting(String writing) {
		this.writing = writing;
	}
	public String getFee() {
		return fee;
	}
	public void setFee(String fee) {
		this.fee = fee;
	}
	public String getFinalTestId() {
		return finalTestId;
	}
	public void setFinalTestId(String finalTestId) {
		this.finalTestId = finalTestId;
	}
}
